#!/bin/bash
# 快速TestSM4固件

echo "=========================================="
echo "  TestSM4固件"
echo "=========================================="
echo ""

# Check固件YesNo存In
if [ ! -f "build/sm4_batch.elf" ]; then
    echo "Error: 固件Not存In，请先编译"
    echo "Run: make"
    exit 1
fi

echo "[1] GenerateTestData（5个Trace）..."
python3 ../generate_test_data.py --algorithm sm4 --traces 5 --output sm4_test_data.h
echo ""

echo "[2] RunQEMUTest（前5个Trace）..."
echo "启动QEMU..."
timeout 10s qemu-system-arm \
    -M netduinoplus2 \
    -nographic \
    -semihosting-config enable=on,target=native \
    -kernel build/sm4_batch.elf | head -50

echo ""
echo "=========================================="
echo "  TestCompleted"
echo "=========================================="
echo ""
echo "If看To TRACE_START And TRACE_END 标记，Description固件工作正常"
echo ""
echo "Use通用Script采集CompleteTrace:"
echo "  cd .."
echo "  python3 collect_firmware_traces.py --algorithm sm4 --traces 100"
